package com.bamanker.cloudsys.service.impl;


import com.bamanker.cloudapi.domain.MyPage;
import com.bamanker.cloudsys.domain.toEmail;
import com.bamanker.cloudsys.mapper.ToEmailMapper;
import com.bamanker.cloudsys.service.ToEmailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author bamanker
 */
@Service
@RequiredArgsConstructor
public class ToEmailServiceImpl extends ServiceImpl<ToEmailMapper, toEmail> implements ToEmailService {

    private final ToEmailMapper toEmailMapper;

    @Override
    public MyPage<toEmail> selectPage(int start, int size) {
        Page<toEmail> querryPage = new Page<>(start, size);
        LambdaQueryWrapper<toEmail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select();
        Page<toEmail> iPage = toEmailMapper.selectPage(querryPage, queryWrapper);

        MyPage<toEmail> myPage = new MyPage<>();
        myPage.setList(iPage.getRecords());
        myPage.setPages(iPage.getPages());
        myPage.setPageNum(iPage.getCurrent());
        myPage.setSize(iPage.getSize());
        myPage.setHasPreviousPage(iPage.hasPrevious());
        myPage.setHasNextPage(iPage.hasNext());
        myPage.setPrePage(iPage.getCurrent() - 1);
        myPage.setNextPage(iPage.getCurrent() + 1);
        long[] navigatepageNums = new long[(int) iPage.getPages()];
        for (int i = 0, l = 1; i < iPage.getPages(); i++) {
            navigatepageNums[i] = l++;
        }
        myPage.setNavigatepageNums(navigatepageNums);
        return myPage;
    }
}
